<template>
	<view>
		<view class="">
			{{myorder}}
		</view>
		<view class="">
			{{myorder}}
		</view>
		<!-- #ifdef MP -->
		<authorize :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize>
		<!-- #endif -->
	</view>
</template>

<script>
const globalData = getApp().globalData;
import { orderPay } from '@/api/order.js';
import { login } from '@/api/public.js';
import { mapGetters } from 'vuex';
import {OPENID,LOGIN_STATUS,USER_INFO} from '@/config/cache';
import Cache from '@/utils/cache';
import authorize from '@/components/Authorize';
export default {
	components: {
		// #ifdef MP
		authorize
		// #endif
	},
	data() {
		return {
			isAuto: false, //没有授权的不会自动授权
			isShowAuth: false, //是否隐藏授权
			order_id:'',
			token:'',
			myorder:''
		};
	},
	methods: {
		goPay: function() {
			let that = this
			uni.showLoading({
				title: '支付中'
			});
			orderPay(that.order_id,{
				openid:Cache.get(OPENID),
				token:that.token
				}).then(res => {
					let status = res.data.status,
						jsConfig = res.data.result.config,
						skiporderId = res.data.result.order_id,
						skipmessage = res.message,
						myorder = that.myorder
					jsConfig.timeStamp = jsConfig.timestamp;
					uni.requestPayment({
						...jsConfig,
						success: function(res) {
							uni.hideLoading();
							uni.navigateBackMiniProgram({
							  extraData: {
							    order_id:skiporderId,
								msg:skipmessage,
								status:status,
								myorder:myorder
							  },
							  success(res) {
							    
							  }
							})
						},
						fail: function(e) {
							console.log(e.errMsg)
							uni.hideLoading();
							uni.navigateBackMiniProgram({
							  extraData: {
							    order_id:skiporderId,
							    msg:e.errMsg,
							    status:status,
								myorder:myorder
							  },
							  success(res) {
							   
							  }
							})
						},
						complete: function(e) {
							console.log(e)
						}
					});
				})
				.catch(err => {
					return that.$util.Tips({
						title: err
					});
				});
		},
		// 授权关闭
		authColse: function(e) {
			this.isShowAuth = e;
		},
		onLoadFun(){//回调
			this.isShowAuth = false;
			this.goPay();
		},
	},
	computed: {...mapGetters(['isLogin'])},
	onLoad: function(options) {
		let that =this
		this.order_id=options.order_id
		this.token=options.token
		this.myorder=options.myorder
		if (that.isLogin == false) {
			// #ifdef H5 || APP-PLUS
			toLogin();
			// #endif 
			// #ifdef MP
			that.isAuto = true;
			that.$set(that, 'isShowAuth', true);
			// #endif
		}
	},
	onShow(option) {
		if (this.isLogin == true) {
			this.isShowAuth = false;
		}
	}
};
</script>

<style></style>
